﻿using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BasicModuleWebApiAuthorization.Controllers
{
    [Route("api/[controller]/page")]
    [ApiController]
    public class PageAuthorizationController : ControllerBase
    {
        public IAuthorizationService  _authorizationService { get; set; }

        public PageAuthorizationController(IAuthorizationService authorizationService)
        {
            this._authorizationService = authorizationService;
        }

        /// <summary>
        /// 页面鉴权
        /// </summary>
        [HttpGet("Authorization")]
        public async  Task<AuthorizationResult> PageAuthorization()
        {
            //页面鉴权
            AuthorizationResult authenticateResult = await _authorizationService.AuthorizeAsync(HttpContext.User, HttpContext, "User");
            return authenticateResult;
        }
    }
}
